package com.liaogui.示例;

import java.lang.ref.WeakReference;
import java.util.WeakHashMap;

/**
 * @author liaogui
 * @date 2025/4/10 10:15
 */
public class WeakHashMapTest {


    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(5000);
        WeakHashMap<String, WeakReference<String>> map = new WeakHashMap<>();
//        String key = "liaogui";
        String key = new String("liaogui");
        map.put(key, new WeakReference<>("liaogui"));
        System.out.println(map.size());
        key = null;
        System.gc();
        Thread.sleep(10000);
        System.out.println(map.size());
    }
}
